var t = getApp(), e = require("../login/base64.js").Base64;

Page({
    data: {
        focusMobile: !0,
        focusCode: !1,
        focusPwd: !1,
        focusPwdConfrim: !1,
        sending: !1,
        last: 60,
        mobile: "",
        code: "",
        pwd: "",
        pwdConfirm: ""
    },
    sendCode: function(e) {
        var a = this;
        if (!/^1[\d]{10}$/.test(this.data.mobile)) return this.alertAndFocus("手机号码不正确", "focusMobile");
        t.request({
            url: t.server + "/smsApi/getCode",
            method: "POST",
            data: {
                mobile: this.data.mobile
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                wx.showToast({
                    icon: "none",
                    title: t.data.msg.zh
                }), 0 === t.data.code && (a.setData({
                    msgId: t.data.result.msg_id
                }), a.startCounter());
            }
        });
    },
    startCounter: function() {
        var t = this;
        this.setData({
            focusCode: !0,
            sending: !0,
            last: 60
        }), this.timer = setInterval(function() {
            var e = t.data.last - 1;
            e > 0 ? t.setData({
                last: e
            }) : (t.setData({
                sending: !1
            }), clearInterval(t.timer));
        }, 1e3);
    },
    toPage: function(t) {
        var e = t.currentTarget.dataset.url;
        wx.navigateTo({
            url: e
        });
    },
    changeVal: function(t) {
        var e = {}, a = t.currentTarget.dataset.name, o = t.detail.value;
        e[a] = o, this.setData(e);
    },
    confirm: function() {
        this.save();
    },
    save: function() {
        return /^1[\d]{10}$/.test(this.data.mobile) ? this.data.msgId ? /^[\d]{6}$/.test(this.data.code) ? this.data.pwd ? this.data.pwdConfrim ? this.data.pwdConfrim !== this.data.pwd ? this.alertAndFocus("两次密码输入不一致", "focusPwdConfrim") : void t.request({
            url: t.server + "/userApi/ourRegister",
            method: "POST",
            data: {
                mobile: this.data.mobile,
                type: 2,
                code: this.data.code,
                msg_id: this.data.msgId,
                is_web: 1,
                password: e.encode(this.data.pwd)
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                wx.showToast({
                    icon: "none",
                    title: t.data.msg.zh
                }), 0 === t.data.code && wx.redirectTo({
                    url: "/pages/usr/login/login"
                });
            }
        }) : this.alertAndFocus("请输确认密码", "focusPwdConfrim") : this.alertAndFocus("请输入密码", "focusPwd") : this.alertAndFocus("请正确输入验证码", "focusCode") : this.alertAndFocus("请先获取验证码", "focusCode") : this.alertAndFocus("手机号码不正确", "focusMobile");
    },
    alertAndFocus: function(t, e) {
        var a = this;
        wx.showToast({
            icon: "none",
            title: t,
            complete: function() {
                var t = {};
                t[e] = !0, a.setData(t);
            }
        });
    },
    onLoad: function(t) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});